<?php

class GetDocent
{
	private $sugar_client;
	private $wsdl;
	
	/* Constructor */
	public function __Construct($arg_wsdl)
	{
		$this->wsdl = $arg_wsdl;
		$this->sugar_client = new nusoapclient($arg_wsdl, true);
	}
	
	/* Geef een array van alle docenten terug */
	public function getDocenten()
	{
		$session_id = $_SESSION['session'];
		$set_entry_params = array(
								  'session' => $session_id,
								  'module_name' => 'st_Docent',
								  'query' => '',
								  'order_by' => '',
								  'select_fields'=>array(
															'id',
															'stamnummer',
															'name',
															'lastname',
															'betweentf',
															'functiontf',
															'phone_number',
															'education',
															'active'
														),
								  'deleted' => false
								  );
		
		//Parse de "ruwe" data naar objecten en geef deze vervolgens terug
		$parser = new Parser($this->wsdl);
		$parser->setResult($this->sugar_client->call('get_entry_list',$set_entry_params));
		
		$docentenArray = $parser->getDocentArray();
		
		$getStages = new GetStage($this->wsdl);
		$stagesArray = $getStages->getStages();
		
		foreach($docentenArray as $docent)
		{
			$docent_id = $docent->getId();
			$stageArray = NULL;
			
			if(sizeof($stagesArray) > 0)
			{
				$stageArray = array();
				
				foreach($stagesArray as $stage)
				{
					$docent1_id = $stage->getDocent();

					if($docent1_id == $docent_id)
					{
						$stageArray[] = $stage;
					}
				}
			}
			
			$docent->setStages($stageArray);
		}
		
		return $docentenArray;
	}
	
	public function getDocent($arg_docent_id)
	{
		$session_id = $_SESSION['session'];
		$set_entry_params = array(
								  'session' => $session_id,
								  'module_name' => 'st_Docent',
								  'id' => $arg_docent_id,
								  'select_fields'=>array(
															'id',
															'stamnummer',
															'name',
															'lastname',
															'betweentf',
															'functiontf',
															'phone_number',
															'education',
															'active'
														)
								  );
		
		//Parse de "ruwe" data naar objecten en geef deze vervolgens terug
		$parser = new Parser($this->wsdl);
		$parser->setResult($this->sugar_client->call('get_entry',$set_entry_params));
		
		$docent = $parser->getDocentArray();
		return $docent[0];
	}
}

?>